import { InjectionKey } from "vue";
import { createStore, Store, useStore as baseUseStore } from "vuex";
import { RootState, AllState } from "./store.type";
import AjaxModule from "./ajax";
import UserModule from "./user";

// const getStoreObj = (source: any) => {
//     let obj = {};
//     Object.keys(source).forEach(key => {
//         obj = merge(true, obj, source[key]);
//     });
//     return obj;
// };
// eslint-disable-next-line symbol-description
export const key: InjectionKey<Store<RootState>> = Symbol('vue-store');
export const store: Store<RootState> = createStore({
    modules: {
        ajax: AjaxModule,
        user: UserModule
    }
});

export function useStore<T = AllState>() {
    return baseUseStore<T>(key);
}
